/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import util.Fixtures.CreditTerm;

/**
 *
 * @author Andy
 */
@Entity(name="CreditTerm")
public class CreditTermEntity extends DataObjectEntity implements Serializable {

    private double creditLimit;
    private int maxRepayTime;  
    private double lateCharges;
    private int discountRepayTime;
    private double discount;
    
    @OneToMany(mappedBy = "creditTerm")
    private Collection<CustomerAccountEntity> customerAccounts = new ArrayList<CustomerAccountEntity>();

    public CreditTermEntity() {
        super();
    }

    public CreditTermEntity(double creditLimit, int maxRepayTime, double lateCharges, 
            int discountRepayTime, double discount) {
        super();
        this.creditLimit = creditLimit;
        this.maxRepayTime = maxRepayTime;
        this.lateCharges = lateCharges;
        this.discountRepayTime = discountRepayTime;
        this.discount = discount;
    }
    

    public double getCreditLimit() {
        return creditLimit;
    }

    public void setCreditLimit(double creditLimit) {
        this.creditLimit = creditLimit;
    }

    public double getDiscount() {
        return discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }

    public int getDiscountRepayTime() {
        return discountRepayTime;
    }

    public void setDiscountRepayTime(int discountRepayTime) {
        this.discountRepayTime = discountRepayTime;
    }

    public double getLateCharges() {
        return lateCharges;
    }

    public void setLateCharges(double lateCharges) {
        this.lateCharges = lateCharges;
    }

    public int getMaxRepayTime() {
        return maxRepayTime;
    }

    public void setMaxRepayTime(int maxRepayTime) {
        this.maxRepayTime = maxRepayTime;
    }

    public Collection<CustomerAccountEntity> getCustomerAccounts() {
        return customerAccounts;
    }

    public void setCustomerAccounts(Collection<CustomerAccountEntity> customerAccounts) {
        this.customerAccounts = customerAccounts;
    }

    @Override
    public String childToString() {
        return "CreditTermEntity{" + "creditLimit=" + creditLimit + ", maxRepayTime=" + maxRepayTime + ", lateCharges=" + lateCharges + ", discountRepayTime=" + discountRepayTime + ", discount=" + discount + ", customerAccounts=" + customerAccounts + '}';
    }
    
    public String getIsDefaultTerm(){
        if (getId()!=null && getId().equals(CreditTerm.Default.getDbId()))
            return "Default";
        else
            return "Customized";
    }
}
